<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>

<head>
    <title>角色管理</title>
</head>

<body>

<div id="wrapper">
    <div  class="gray-bg">
        <div class="row m-t-sm">
            <div class="col-lg-12">
                <ol class="breadcrumb f-fl">
                    <li>
                        <i class="fa fa-location-arrow"></i>   <a>系统管理</a>
                    </li>
                    <li class="active">
                        <strong>角色管理</strong>
                    </li>
                </ol>
                <span class="navbar-right  m-r m-t-8"><a href="javascript:history.go(-1);" class="btn-primary btn-add "> <i class='fa fa-mail-reply'></i> 返回</a></span>

            <%--<span class="navbar-right  m-r m-t-8"><a href="${ctx}/admin/user/add" class="btn-primary btn-add "> <i class='fa fa-plus-square-o'></i> 新 增</a></span>--%>
            </div>
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">
           <div class="fh-breadcrumb">
            <div class="fh-column">
                <div class="full-height-scroll">
                    <ul class="list-group elements-list">
                        <li class="">
                            <div id="module_tree">
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

           <div class="full-height">
            <div class="full-height-scroll white-bg border-left">
                    <div class="tab-content">
                        <div class="row wrapper wrapper-content">
                            <div class="col-sm-12">
                                <form id="form" method="get" class="form-horizontal" form-before="before()"  data-ajax="${ctx}/admin/sys/role/list"   action="${ctx}/admin/sys/role/${method}">
                                    <input  type="hidden" name="permIds" id="permIds" value="${permIds}"/>
                                    <input  type="hidden" name="roleId" id="roleId" value="${role.roleId}"/>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">角色名</label>
                                        <div class="col-sm-6">
                                            <input type="text" name="roleName" class="form-control" id="roleName" value="${role.roleName}" placeholder="请输入角色名" required="true" />
                                        </div>
                                    </div>
                                <%--    <div class="form-group">
                                        <label class="col-sm-3 control-label">角色排序</label>
                                        <div class="col-sm-6">
                                            <input type="text" name="roleSort" class="form-control" value="${role.roleSort}" placeholder="请输入角色排序"   />
                                        </div>
                                    </div>--%>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">模块说明</label>
                                        <div class="col-sm-6">
                                            <input type="text" name="des" class="form-control" value="${role.des}" placeholder="请输入模块说明"  />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-3">
                                            <button class="btn btn-primary" type="submit">保存</button>
                                            <a class="btn btn-white " href="javascript:history.go(-1)">取消</a>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                </div>
            </div>
        </div>
       </div>
    </div>
</div>



<!-- Page-Level Scripts -->
<script>
    $(document).ready(function(){
        $('#module_tree').jstree(
                {
                'plugins':["wholerow","checkbox"],
                'core' : {
                    'data' :{
                        'url': '${ctx}/admin/sys/role/tree?rid=${role.roleId}',  //异步加载jstree html格式的数据地址
                        'data': function (node) {
                            return { 'id': node.id };
                        }
                    }
                }/*,
                "checkbox" : {
                    "three_state":false,
                    "cascade" : "up+down+undetermined"
                },*/
                }).on("activate_node.jstree", function (e, data) {
                     $("#permIds").val(get_checked);
                  });

    });

    var before =function(){

         if(get_checked().length<=0){
             parent.layer.alert("请选择模块");
             return false;
         }

        var roleName=$("#roleName").val();
        var roleId=$("#roleId").val();

        var relt;
        $.ajax({
            url: "${ctx}/admin/sys/role/existed",
            method: "POST",
            async: false,
            data: {"roleName" : roleName,"roleId":roleId},
            dataType: "json",
            success : function(response) {
                if (response.success) {
                    relt= true;
                } else {
                    parent.layer.alert(roleName+'已存在');
                    relt = false;
                }
            }
        });
        return relt;
    }

    var  get_checked =function(){
        var ids="";
        var nodes=$("#module_tree").jstree("get_checked"); //使用get_checked方法
        $.each(nodes, function(i, n) {
            ids += n+",";
        });
        if(ids.length>0) ids =ids.substring(0,ids.length-1)
       return ids;
    }

</script>

</body>

</html>
